package logic

import (
	"context"
	"srv/renrenzu"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodAddLogic) GoodAdd(req *types.GoodAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.RenRemZu.GoodAdd(l.ctx, &renrenzu.GoodAddRequest{
		GoodsTitle:      req.GoodsTitle,
		GoodsCover:      req.GoodsCover,
		GoodsPrice:      float32(req.GoodsPrice),
		GoodsStock:      req.GoodsStock,
		GoodsCollection: req.GoodsCollection,
		GoodsState:      req.GoodsState,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "商品添加成功",
		Code: 200,
		Data: map[string]interface{}{
			"goodsId": add,
		},
	}, nil
	return
}
